package com.bw.service;

import com.alibaba.fastjson.JSON;
import com.bw.dao.GoodsDao;
import com.bw.pojo.Goods;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/***************************
 FileAction:

 CreateTime:2022-07-27 15:03
 Author:Aaking-aline
 ****************************/
@Service
public class GoodsService {

	@Autowired
	private GoodsDao goodsDao;


	public void insertGoods(Goods goods){

	}

	public void deleteGoods(String id){

	}

	public void updateGoods(Goods goods){

	}

	public String selectAllGoods(){
		List<Goods> goods = goodsDao.selectAllGoods();
		return JSON.toJSONString(goods);
	}

	public String selectGoodsOrderByPrice(){
		List<Goods> goods = goodsDao.selectGoodsOrderByPrice();
		return JSON.toJSONString(goods);
	}

	public String selectGoodsLimit(String page,String num){
		Integer index = (Integer.parseInt(page) - 1) * Integer.parseInt(num);

		System.out.println(index + " : " + num);

		List<Goods> goods = goodsDao.selectGoodsLimit(index,Integer.parseInt(num));
		return JSON.toJSONString(goods);
	}

}
